jun.BankWin = Ext.extend(Ext.Window, {
    title: 'Bank',
    modez: 1,
    width: 400,
    height: 225,
    layout: 'form',
    modal: true,
    padding: 5,
    closeForm: false,
    initComponent: function() {
        this.items = [{
            xtype: 'form',
            frame: false,
            bodyStyle: 'background-color: #E4E4E4; padding: 10px',
            id: 'form-Bank',
            labelWidth: 100,
            labelAlign: 'left',
            layout: 'form',
            ref: 'formz',
            border: false,
            items: [{
                xtype: 'textfield',
                fieldLabel: 'Nama Akun',
                hideLabel: false,
                name: 'nama_akun',
                id: 'nama_akunid',
                ref: '../nama_akun',
                maxLength: 30,
                anchor: '100%'
            }, {
                xtype: 'textfield',
                fieldLabel: 'No. Rekening',
                hideLabel: false,
                name: 'no_rekening',
                id: 'no_rekeningid',
                ref: '../no_rekening',
                maxLength: 50,
                anchor: '100%'
            }, {
                xtype: 'textfield',
                fieldLabel: 'Nama Bank',
                hideLabel: false,
                name: 'nama_bank',
                id: 'nama_bankid',
                ref: '../nama_bank',
                maxLength: 50,
                anchor: '100%'
            }, {
                xtype: 'textfield',
                fieldLabel: 'Alamat Bank',
                hideLabel: false,
                name: 'alamat_bank',
                id: 'alamat_bankid',
                ref: '../alamat_bank',
                maxLength: 225,
                anchor: '100%'
            }, {
                xtype: 'textfield',
                fieldLabel: 'No. Telp',
                hideLabel: false,
                name: 'no_tlp',
                id: 'no_tlpid',
                ref: '../no_tlp',
                maxLength: 30,
                anchor: '100%'
            }, ]
        }];
        this.fbar = {
            xtype: 'toolbar',
            items: [{
                xtype: 'button',
                text: 'Simpan',
                hidden: false,
                ref: '../btnSave'
            }, {
                xtype: 'button',
                text: 'Simpan & Tutup',
                ref: '../btnSaveClose'
            }, {
                xtype: 'button',
                text: 'Batal',
                ref: '../btnCancel'
            }]
        };
        jun.BankWin.superclass.initComponent.call(this);
        this.btnSaveClose.on('click', this.onbtnSaveCloseClick, this);
        this.btnSave.on('click', this.onbtnSaveclick, this);
        this.btnCancel.on('click', this.onbtnCancelclick, this);
        if (this.modez == 1 || this.modez == 2) {
            this.btnSave.setVisible(false);
        } else {
            this.btnSave.setVisible(true);
        }
    },
    btnDisabled: function(status) {
        this.btnSave.setDisabled(status);
        this.btnSaveClose.setDisabled(status);
    },
    saveForm: function() {
        this.btnDisabled(true);
        var urlz;
        if (this.modez == 1 || this.modez == 2) {
            urlz = 'Bank/update';
        } else {
            urlz = 'Bank/create';
        }
        Ext.getCmp('form-Bank').getForm().submit({
            url: urlz,
            timeOut: 1000,
            scope: this,
            params: {
                id: this.id
            },
            success: function(f, a) {
                jun.rztBank.reload();
                var response = Ext.decode(a.response.responseText);
                Ext.MessageBox.show({
                    title: 'Info',
                    msg: response.msg,
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.INFO
                });
                if (this.modez == 0) {
                    Ext.getCmp('form-Bank').getForm().reset();
                    this.btnDisabled(false);
                }
                if (this.closeForm) {
                    this.close();
                }
            },
            failure: function(f, a) {
                var response = Ext.decode(a.response.responseText);
                Ext.MessageBox.show({
                    title: 'Warning',
                    msg: response.msg,
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                });
                this.btnDisabled(false);
            }
        });
    },
    onbtnSaveCloseClick: function() {
        this.closeForm = true;
        this.saveForm(true);
    },
    onbtnSaveclick: function() {
        this.closeForm = false;
        this.saveForm(false);
    },
    onbtnCancelclick: function() {
        this.close();
    }
});